.\"
.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
.\" permission to reproduce portions of its copyrighted documentation.
.\" Original documentation from The Open Group can be obtained online at
.\" http://www.opengroup.org/bookstore/.
.\"
.\" The Institute of Electrical and Electronics Engineers and The Open
.\" Group, have given us permission to reprint portions of their
.\" documentation.
.\"
.\" In the following statement, the phrase ``this text'' refers to portions
.\" of the system documentation.
.\"
.\" Portions of this text are reprinted and reproduced in electronic form
.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
.\" Standard for Information Technology -- Portable Operating System
.\" Interface (POSIX), The Open Group Base Specifications Issue 6,
.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
.\" Engineers, Inc and The Open Group.  In the event of any discrepancy
.\" between these versions and the original IEEE and The Open Group
.\" Standard, the original IEEE and The Open Group Standard is the referee
.\" document.  The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
.\" This notice shall appear on any product containing this material.
.\"
.\" The contents of this file are subject to the terms of the
.\" Common Development and Distribution License (the "License").
.\" You may not use this file except in compliance with the License.
.\"
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
.\" or http://www.opensolaris.org/os/licensing.
.\" See the License for the specific language governing permissions
.\" and limitations under the License.
.\"
.\" When distributing Covered Code, include this CDDL HEADER in each
.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
.\" If applicable, add the following below this CDDL HEADER, with the
.\" fields enclosed by brackets "[]" replaced with your own identifying
.\" information: Portions Copyright [yyyy] [name of copyright owner]
.\"
.\"
.\" Copyright 1989 AT&T
.\" Portions Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.
.\" Copyright (c) 2004, Sun Microsystems, Inc.  All Rights Reserved.
.\"
.TH WAITID 2 "Jun 8, 2018"
.SH NAME
waitid \- wait for child process to change state
.SH SYNOPSIS
.LP
.nf
#include <wait.h>

\fBint\fR \fBwaitid\fR(\fBidtype_t\fR \fIidtype\fR, \fBid_t\fR \fIid\fR, \fBsiginfo_t *\fR\fIinfop\fR, \fBint\fR \fIoptions\fR);
.fi

.SH DESCRIPTION
.LP
The \fBwaitid()\fR function suspends the calling process until one of its child
processes changes state. It records the current state of a child in the
structure pointed to by \fIinfop\fR. It returns immediately if a child process
changed state prior to the call.
.sp
.LP
The \fIidtype\fR and  \fIid\fR arguments specify which children  \fBwaitid()\fR
is to wait for, as follows:
.RS +4
.TP
.ie t \(bu
.el o
If  \fIidtype\fR is \fBP_PID\fR, \fBwaitid()\fR waits for the child with a
process \fBID\fR equal to \fB(pid_t)\fR\fIid\fR.
.RE
.RS +4
.TP
.ie t \(bu
.el o
If \fIidtype\fR is \fBP_PGID\fR,  \fBwaitid()\fR waits for any child with a
process group \fBID\fR equal to \fB(pid_t)\fR\fIid\fR.
.RE
.RS +4
.TP
.ie t \(bu
.el o
If \fIidtype\fR is \fBP_ALL\fR, \fBwaitid()\fR waits for any child and \fIid\fR
is ignored.
.RE
.sp
.LP
The \fIoptions\fR argument is used to specify which state changes
\fBwaitid()\fR is to wait for. It is formed by bitwise \fBOR\fR operation of
any of the following flags:
.sp
.ne 2
.na
\fB\fBWCONTINUED\fR\fR
.ad
.RS 14n
Return the status for any child that was stopped and has been continued.
.RE

.sp
.ne 2
.na
\fB\fBWEXITED\fR\fR
.ad
.RS 14n
Wait for process(es) to exit.
.RE

.sp
.ne 2
.na
\fB\fBWNOHANG\fR\fR
.ad
.RS 14n
Return immediately.
.RE

.sp
.ne 2
.na
\fB\fBWNOWAIT\fR\fR
.ad
.RS 14n
Keep the process in a waitable state.
.RE

.sp
.ne 2
.na
\fB\fBWSTOPPED\fR\fR
.ad
.RS 14n
Wait for and return the process status of any child that has  stopped upon
receipt of a signal.
.RE

.sp
.ne 2
.na
\fB\fBWTRAPPED\fR\fR
.ad
.RS 14n
Wait for traced process(es) to become trapped or reach a breakpoint (see
\fBptrace\fR(3C)).
.RE

.sp
.LP
The \fIinfop\fR argument must point to a \fBsiginfo_t\fR structure, as defined
in \fBsiginfo.h\fR(3HEAD). If \fBwaitid()\fR returns because a child process
was found that satisfies the conditions indicated by the arguments \fIidtype\fR
and \fIoptions\fR, then the structure pointed to by \fIinfop\fR will be filled
by the system with the status of the process. The \fBsi_signo\fR member will
always be equal to \fBSIGCHLD\fR.
.sp
.LP
One instance of a \fBSIGCHLD\fR signal is queued for each child process whose
status has changed. If \fBwaitid()\fR returns because the status of a child
process is available and \fBWNOWAIT\fR was not specified in \fIoptions\fR, any
pending \fBSIGCHLD\fR signal associated with the process ID of that child
process is discarded. Any other pending \fBSIGCHLD\fR signals remain pending.
.SH RETURN VALUES
.LP
If \fBwaitid()\fR returns due to a change of state of one of its children and
\fBWNOHANG\fR was not used,  \fB0\fR is returned.  Otherwise, \fB\(mi1\fR is
returned and  \fBerrno\fR is set to indicate the error. If \fBWNOHANG\fR was
used,  \fB0\fR can be returned (indicating no error); however, no children may
have changed state if \fBinfop->si_pid\fR is \fB0\fR.
.SH ERRORS
.LP
The \fBwaitid()\fR function will fail if:
.sp
.ne 2
.na
\fB\fBECHILD\fR\fR
.ad
.RS 10n
The set of processes specified by \fIidtype\fR and \fIid\fR does not contain
any unwaited processes.
.RE

.sp
.ne 2
.na
\fB\fBEFAULT\fR\fR
.ad
.RS 10n
The \fIinfop\fR argument points to an illegal address.
.RE

.sp
.ne 2
.na
\fB\fBEINTR\fR\fR
.ad
.RS 10n
The \fBwaitid()\fR function was interrupted due to the receipt of a signal by
the calling process.
.RE

.sp
.ne 2
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 10n
An invalid value was specified for \fIoptions\fR, or \fIidtype\fR and \fIid\fR
specify an invalid set of processes.
.RE

.SH USAGE
.LP
With \fIoptions\fR equal to \fBWEXITED\fR | \fBWTRAPPED\fR, \fBwaitid()\fR is
equivalent to \fBwaitpid\fR(3C). With \fIidtype\fR equal to \fBP_ALL\fR and
\fIoptions\fR equal to \fBWEXITED\fR | \fBWTRAPPED\fR, \fBwaitid()\fR is
equivalent to \fBwait\fR(3C).
.SH ATTRIBUTES
.LP
See \fBattributes\fR(7) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Interface Stability	Standard
_
MT-Level	Async-Signal-Safe
.TE

.SH SEE ALSO
.LP
.BR Intro (2),
.BR exec (2),
.BR exit (2),
.BR fork (2),
.BR pause (2),
.BR sigaction (2),
.BR ptrace (3C),
.BR signal (3C),
.BR wait (3C),
.BR waitpid (3C),
.BR siginfo.h (3HEAD),
.BR attributes (7),
.BR standards (7)
